package com.study.demo_resource.runner;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @Name: InitRunner
 * @Description: java类作用描述
 * @Author: yn
 * @CreateDate: 2022/9/6 14:40
 * @Remark: 特殊说明
 * @Version: 1.0
 */
@Component
public class InitRunner implements ApplicationRunner {
	private final ResourceLoader resourceLoader;
	private final PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver;

	InitRunner(ResourceLoader resourceLoader){
		this.resourceLoader = resourceLoader;
		this.pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver(this.getClass().getClassLoader());
	}

	@Override
	public void run(ApplicationArguments args) throws Exception {
		InputStream inputStream = resourceLoader.getResource("classpath:application.properties").getInputStream();
		BufferedReader reader=new BufferedReader(new InputStreamReader(inputStream));
		while (reader.ready()){
			System.out.println(reader.readLine());
		}
		inputStream.close();

		for (Resource resource : pathMatchingResourcePatternResolver.getResources("classpath*:**/Long.class")) {
			System.out.println(resource.getURL());
		}
	}
}
